#include <bits/stdc++.h>

int n;  // 节点数
std::vector<int> tree[100010];  //邻接表，存储树的结构
int deep1[100010];   //记录每个节点的深度  从任意点出发
int deep2[100010];   //记录每个节点的深度  从deep1的最远点出发

// 从x出发的各个结点的深度递归
void dfs(int x, int fa, int d,int deep[]) {
    deep[x] = d;
    for (int i = 0; i < tree[x].size(); i++) {
        int y = tree[x][i];
        if (y == fa) {
            continue;
        }
        dfs(y, x, d + 1,deep);
    }
}

int main(int argc, char** argv) {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::cin >> n;
    for (int i = 1; i <= n - 1; i++) {
        int x, y;
        std::cin >> x >> y;
        tree[x].push_back(y);
        tree[y].push_back(x);
    }

    dfs(1, 0, 0, deep1);
    int left = std::max_element(deep1+1, deep1 + n + 1) - deep1;
    dfs(left, 0, 0, deep2);
    int right = std::max_element(deep2+1, deep2 + n + 1) - deep2;
    std::cout << deep2[right] << std::endl;
    return 0;
}


